package com.kfm.boot.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect // 标记这个类是一个切面类
@Component
public class MyAOP {

    @Pointcut("execution(* com.kfm.boot.service.*.*(..))")
    public void pt(){};

    @Before("pt()")
    public void before(JoinPoint joinPoint){
        System.out.println("前置通知");
    }

    @After("pt()")
    public void after(){
        System.out.println("后置通知");
    }

    @AfterThrowing("pt()")
    public void afterThrowing(){
        System.out.println("异常通知");
    }

    @AfterReturning("pt()")
    public void afterReturning(){
        System.out.println("返回通知");
    }

//    @Around("pt()")
//    public Object around(ProceedingJoinPoint pjp) throws Throwable {
//        System.out.println("前置通知");
//        Object proceed = null;
//        try{
//            proceed = pjp.proceed(); // 执行目标方法
//            System.out.println("返回通知");
//        } catch (Exception ex){
//            System.out.println("异常通知");
//        } finally {
//            System.out.println("最终通知");
//        }
//        return proceed;
//    }

}
